package com.woniuxy03;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-05-28 15:51
 */
public class Game {
    //统计次数
    int count;
    Computer computer;
    User user;
//    public void initGame(){
//        computer=new Computer();
//        user=new User();
//        count=0;
//    }

    public Game(){
        computer=new Computer();
        user=new User();
        count=0;
    }

    //控制游戏流程
    public void startGame(){
        Scanner sc=new Scanner(System.in);
        String answer=null;
        do{
            count++;
            int userShow = user.show();
            System.out.println(user.showName(userShow));
            int computerShow = computer.show();
            System.out.println(computer.showName(computerShow));
            //判断胜负
            judgeOne(userShow, computerShow);
            System.out.println("是否继续下一局");
            answer = sc.next();
        }while (answer.equals("y"));
        judgeResult();
    }
    public void judgeOne(int userShow, int computerShow) {
        if ((userShow == 1 && computerShow == 3) || (userShow == 2 && computerShow == 1) || (userShow == 3 && computerShow == 2)) {
            user.winCount++;
            System.out.println("用户获胜");
        } else if (userShow == computerShow) {
            System.out.println("平局");
        } else {
            computer.winCount++;
            System.out.println("电脑获胜");
        }
    }
    public void judgeResult(){
        if(user.winCount>computer.winCount){
            System.out.println("user wins");
        }else if(user.winCount==computer.winCount){
            System.out.println("平局");
        }else{
            System.out.println("computer wins");
        }
    }
}
